<?php

namespace WeChat\Controller;

class TestController extends BaseController {

    protected function _initialize() {
        parent::_initialize();
    }

    /*
     * 前台首页展示
     */

    public function index() {
        
        
        $aa = array();
        dump($aa);
        
        for($i = 1; $i < 5; $i++){
            
            $aa = $i;
            dump($aa);
        }
        dump($aa);exit;
        
        
        dump($aa);exit;
        
        
        $a = get_time(1,1,1);
        dump($a);exit;
        
        
         $b = D('Order')->get_order_amount_today();

        dump($b);
        exit;

//        dump(empty('0.00'));

//        $a = D('MemberTeamdividend')->member_teamdividend('6065');
//
//        dump($a);
//        exit;

        $model = D('Member');
        $a = $model->get_members_fullback(2,3);

        dump($a);
        exit;
    }

    public function test() {

        $category = array(
            '0' => array(
                'id' => '201',
                'title' => 'cate01'
            ),
            '1' => array(
                'id' => '202',
                'title' => 'cate02'
            ),
            '2' => array(
                'id' => '203',
                'title' => 'cate03'
            ),
        );
        
        $a = $this->index($category);

        $goods = array(
            '0' => array(
                'id' => 101,
                'cate_id' => '201',
                'title' => 'cate01'
            ),
            '1' => array(
                'id' => 102,
                'cate_id' => '201',
                'title' => 'cate01'
            ),
            '2' => array(
                'id' => 103,
                'cate_id' => '203',
                'title' => 'cate01'
            ),
            '3' => array(
                'id' => 104,
                'cate_id' => '203',
                'title' => 'cate01'
            )
        );
        
        
        foreach($category as $k=>$v){
            
              $id = $v['id'];
           
            foreach($goods as $gk=>$gv){
                
                $cate_id = $gv['cate_id'];
                
                if($cate_id == $id){
                    
                    $category[$k]['goods'][] = $gv;
                }
            }
            
        }
        
        dump($category[0]['goods']);exit;
    }
    
    
    public  function  add_member(){
        
        $count = 20;
        
        $p = 0;  //0普通会员  1推荐会员
        
        $start_id = D('Member')->max('id');
        
        for($i = 1; $i < $count; $i++){
            
            
            if($p){
                
            }else{
                
                $data[] = array(
                    'id' => $start_id + $i,
                    'pid' => $start_id + $i,
                    'lft' => 0,
                    'rgt' => 1,
                    'lvl' => 0,
                    'total_spend' => 1000 +$i,
                    'flag' => $start_id + $i
                );
                
            }
            
        }
        
        $rows = D('Member')->addAll($data);
        
        return $rows;
    }
    
    
    public  function  deal_same_array(){
        
        $members = array(
            '0'=> array(
                'id'=> 1,
                'pid'=> 1001,
                'name'=> 10,
            ),
            '1'=> array(
                'id'=> 2,
                'pid'=> 1002,
                'name'=> 11,
            ),
            '2'=> array(
                'id'=> 3,
                'pid'=> 1003,
                'name'=> 12,
            ),
            '3'=> array(
                'id'=> 4,
                'pid'=> 1001,
                'name'=> 13,
            ),
            '4'=> array(
                'id'=> 5,
                'pid'=> 1002,
                'name'=> 14,
            ),
            '5'=> array(
                'id'=> 6,
                'pid'=> 1001,
                'name'=> 15,
            ),
        );
        
        $members_team = array();
        
//        foreach ($members as $k => $v) {
//
//            $pid = $v['pid'];
//
//            foreach ($members as $kk => $vv) {
//
//                $spid = $vv['pid'];
//                
//                if ($spid == $pid) {
//
//                    $members_team[$pid][] = $vv;
//
//                    unset($members[$kk]);
//                }
//            }
//        }
        
        foreach($members as $k=>$v){
            
            $members_team[$v['pid']][] = $v;
            
        }
        
        dump($members_team);
        
//        foreach($members_team as $k=>$v){
//            dump($v);
//        }
        exit;
    }

}
